{extend name="admin@index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">订单管理</div>
    <div class="layui-card-body">
        <table class="layui-hide" id="currentTable" lay-filter="currentTable"
               data-auth-add="{:$auth->check('order.order1/add')}"
               data-auth-edit="{:$auth->check('order.order1/edit')}"
               data-auth-delete="{:$auth->check('order.order1/del')}"
        ></table>
    </div>
</div>
<script type="text/html" id="picTpl">
    <img style="max-width:80px; max-height:30px;" src="{{d.avatarUrl}}" data-image="{{d.nickname}}">
</script>
<!--status 1待支付 2待发货 3待收货 4已完成 5已评价 6售后退货 7已取消  pay_status 0未支付 1已支付 2已退款 is_tui 0未退 1已退-->
<script type="text/html" id="barTool">
    <a data-open='{:url("goods_list")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs {:$auth->check('order.order1/goods_list')?'':'layui-hide'}"
       title="订单商品">订单商品</a>

    {{# if(d.delive_type==2){ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" data-open='{:url("shopinfo")}?id={{ d.id }}' data-title="提货商店"
       data-full="true">提货商店</a>
    {{# } }}

    {{# if(d.status==2){ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" data-open='{:url("send")}?id={{ d.id }}' data-title="发货"
       data-full="true">发货</a>
    {{# } }}

    {{# if(d.status==3){ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" data-open='{:url("send")}?id={{ d.id }}' data-title="修改发货"
       data-full="true">修改发货</a>
    {{# } }}

    {{# if((d.status==1||d.status==4||d.status==5||d.status==6||d.status==9)&&d.delive_type==1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" data-open='{:url("sendMsg")}?id={{ d.id }}' data-title="发货信息"
       data-full="true">发货信息</a>
    {{# } }}

<!--    1待支付 2待发货 3待收货 4已完成 5已评价 6售后退货 7已取消 8待取货 9助力中 10砍价发起-->
    {{# if((d.status==2||d.status==3||d.status==4||d.status==5||d.status==8)&&d.is_tui==0&&d.pay_type==1){ }}
    <a data-open='{:url("refund")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs layui-btn-danger {:$auth->check('order.order1/refund')?'':'layui-hide'}"
       title="查看订单">后台退款</a>
    {{# } }}

<!--    {{# if((d.status==2||d.status==7)&&(d.pay_type==2||d.pay_type==3||d.pay_type==5)){ }}-->
<!--            <a href="javascript:;" onclick="wk.confirm('{{d.id}}','{:url('refund2')}','确定后台退款吗？')"-->
<!--           class="layui-btn layui-btn-danger layui-btn-xs {:$auth->check('order.order1/edit')?'':'layui-hide'}" title="后台退款">后台退款2</a>-->
<!--    {{# } }}-->
</script>


<!--操作模板-->

{/block}
{block name="script"}
<script>
    var selectElement = null;
    layui.use('yznTable', function () {
        var table = layui.yznTable;

        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: "{:url('add')}",
            edit_url: "{:url('edit')}",
            delete_url: "{:url('del')}",
        };
        var proviec = {:json_encode($proviec)};
        table.render({
            init: init,
            autoWidth: true,
            toolbar: ['refresh',],
            url: '{:url("index")}',
            cols: [
                [
                    //预约时间 是否分派 陪诊服务 陪诊人员 会员折扣 优惠卷金额
                    // {type: 'checkbox', fixed: 'left'},
                    {field: 'id', width: '4%', title: 'ID',search:false},
                    {field: 'order_no', align: "center", width: '18%', title: '订单编号'},
                    {field: 'nickname', align: "center", width: '10%', title: '下单会员'},
                    {field: 'activity_id', align: "center", width: '10%', title: '助力活动id'},
                    {field: 'mobile', align: "center", width: '10%', title: '会员电话'},
                    {field: 'avatarUrl', align: "center", width: '10%', title: '用户头像', templet: '#picTpl',search:false},
                    {field: 'order_type', align: "center", width: '10%', title: '订单类型', templet: function (d) {
                            if (d.order_type == 1) {
                                return '<span style="color: orangered">助力订单</span>';
                            }if (d.order_type == 2) {
                                return '<span style="color: #2A57FE">直接购买</span>';
                            } else {
                                return '<span style="color:  #00B7EE ">会员订单</span>';
                            }
                        // else if (d.pin_type == 2) {
                        //         return '<span style="color:  #00B7EE ">直接购买</span>';
                        //     }
                        }, selectList: {1:'助力订单',2:'直接购买',3:'会员订单'}
                    },
                    {
                        field: 'status', align: "center", width: '10%', title: '订单状态', templet: function (d) {
                            if (d.status == 1) {
                                return '<span style="color: orangered">待支付</span>';
                            } else if (d.status == 2) {
                                return '<span style="color:  #00B7EE ">待发货</span>';
                            } else if (d.status == 3) {
                                return '<span style="color: #0000FF">待收货</span>';
                            } else if (d.status == 4) {
                                return '<span style="color: #006699">已完成</span>';
                            } else if (d.status == 5) {
                                return '<span style="color: red">已评价</span>';
                            }else if (d.status == 6) {
                                return '<span style="color:green">售后退货</span>';
                            }else if (d.status == 7) {
                                return '<span style="color: #cf9236">已取消</span>';
                            }else if (d.status == 8) {
                                return '<span style="color:green">待取货</span>';
                            }else if (d.status == 9) {
                                return '<span style="color: #00a0e9">助力中</span>';
                            } else if (d.status == 10) {
                                return '<span style="color: #00a0e9">助力发起中</span>';
                            }else {
                                return '<span>未知</span>';
                            }
                        }, selectList: {1:'待支付',2:'待发货',3:'待收货',4:'已完成',7:'已取消',8:'待取货',9:'助力中'}
                    },
                    {field: 'create_time', align: "center", width: '15%', title: '创建时间', search: 'range'},
                    {field: 'pay_time', align: "center", width: '15%', title: '支付时间', search: 'range'},
                    {field: 'finish_time', align: "center", width: '15%', title: '完成时间', search: 'range'},
                    {
                        field: 'pay_status', align: "center", width: '8%', title: '支付状态', templet: function (d) {
                            if (d.pay_status == 0) {
                                return '<span style="color: red">未支付</span>';
                            } else if (d.pay_status == 1) {
                                return '<span style="color: green">已支付</span>';
                            }else if (d.pay_status == 2) {
                                return '<span style="color: #c0ccda">已退款</span>';
                            } else {
                                return '<span>未知</span>';
                            }
                        }, selectList: {0:'未支付',1:'已支付',2:'已退款'}
                    },
                    // {
                    //     field: 'pay_type', align: "center", width: '10%', title: '支付方式', templet: function (d) {
                    //         if (d.pay_type == 1) {
                    //             return '<span style="color:green ">微信支付</span>';
                    //         } else if (d.pay_type == 2) {
                    //             return '<span style="color: #00a0e9">拼团卷支付</span>';
                    //         }else{
                    //             return '<span>未知</span>';
                    //         }
                    //     }, selectList: {1:'微信支付',2:'卷支付'}
                    // },
                    // {
                    //     field: 'delive_type', align: "center", width: '10%', title: '配送方式', templet: function (d) {
                    //         if (d.delive_type == 1) {
                    //             return '<span style="color:green ">快递订单</span>';
                    //         } else if (d.delive_type == 2) {
                    //             return '<span style="color: red">自提订单</span>';
                    //         }else{
                    //             return '<span>未知</span>';
                    //         }
                    //     }, selectList: {1:'快递订单',2:'自提订单'}
                    // },
                    {field: 'origin_price', align: "center", width: '10%', title: '商品金额',search:false},
                    // {field: 'vip_discount', align: "center", width: '10%', title: '会员折扣金额',search:false},
                    // {field: 'pin_coupon', align: "center", width: '10%', title: '拼团卷金额',search:false},
                    {field: 'deliver_money', align: "center", width: '10%', title: '运费',search:false},
                    {field: 'shop_coupon_money', align: "center", width: '10%', title: '积分抵扣金额',search:false},
                    {field: 'order_money2', align: "center", width: '10%', title: '订单金额',search:false},
                    {field: 'pay_money', align: "center", width: '10%', title: '实际支付金额',search:false},
                    {field: 'tui_moeny', align: "center", width: '10%', title: '退款金额',search:false},

                    {field: 'goods_info', align: "center", width: '20%', title: '商品信息',search:false},
                    {field: 'phone12', align: "center", width: '15%', title: '联系人/电话',search:false},
                    {field: 'all_address', align: "center", width: '25%', title: '收货地址',search:false},
                    { fixed: 'right',align: 'center',width: '20%', title: '操作',toolbar: '#barTool' }
                ]
            ],
            page: {}
        });
        yznTable.bindevent();
        // selectElement = document.getElementById('c-province');
        // selectElement.setAttribute("lay-filter", "c-province");
        // form1();
        selectElement2 = document.getElementById('searchFieldset_currentTable');
        selectElement2.classList.remove("layui-hide");
        var element = document.getElementById('layui-input-search');
        element.parentNode.removeChild(element);

    });

    function form1() {
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(c-province)', function (data) {
                console.log(data.value);
                $.ajax({
                    type: "POST",//规定传输方式
                    url: "{:url('getc_cate')}",//提交URL
                    data: {'id': data.value},//提交的数据
                    success: function (result) {
                        if (result.code == 200) {
                            $("#c-city").empty();
                            var str = "<option value>- 全部 -</option>";
                            $.each(result.data, function (i, val) {
                                str += '<option value=' + val.id + '>' + val.name + '</option>'
                            });
                            $("#c-city").append(str);
                            layui.form.render('select');
                        }
                    },
                    error: function () {
                        alert("获取信息失败")
                    }
                });
            })
        });
    }


</script>
{/block}